package app

import (
	"clientDemo/service/asynccall"
	cond "clientDemo/service/cond"
	cond2 "clientDemo/service/cond/cond"
	"clientDemo/service/config_mod"
	"clientDemo/service/growth"
	"clientDemo/service/log"
	login_mod "clientDemo/service/login-mod"
	"clientDemo/service/mission"
	"clientDemo/service/modulemgr"
	modulemgr2 "clientDemo/service/modulemgr/modulemgr"
	"clientDemo/service/variable"
	"clientDemo/ui/fyne_ui/scene"
	"fmt"
)

var _app = &AppModule{
	//SerModule: service.NewConfigModule(),
}

func Get() *AppModule {
	return _app
}

type AppModule struct {
	modManager modulemgr.IModuleManager
}

//func NewApp() *App {
//	return &AppModule{
//		SerModule: service.NewConfigModule(),
//	}
//}

func (m *AppModule) Run() {
	m.modManager = modulemgr2.Get()
	err := m.modManager.RegisterModule(cond.Name, cond2.NewCondModule())
	if err != nil {
		return
	}
	err = m.modManager.RegisterModule(mission.Name, mission.NewMissionModule())
	if err != nil {
		return
	}
	//err = m.modManager.RegisterModule(event.Name, event.NewEventModule())
	//if err != nil {
	//	return
	//}
	err = m.modManager.RegisterModule(growth.Name, growth.NewGrowthModule())
	if err != nil {
		return
	}
	err = m.modManager.RegisterModule(variable.Name, variable.NewVariableModule())
	if err != nil {
		return
	}
	err = m.modManager.RegisterModule(asynccall.Name, asynccall.NewTimerModule())
	if err != nil {
		return
	}
	err = m.modManager.RegisterModule(config_mod.Name, config_mod.NewConfigModule())
	if err != nil {
		return
	}
	err = m.modManager.RegisterModule(login_mod.Name, login_mod.NewLoginModule())
	if err != nil {
		return
	}
	err = m.modManager.RegisterModule(scene.Name, scene.NewSceneModule())
	if err != nil {
		return
	}
	if ok, e := m.modManager.RunAll(); ok == false || e != nil {
		log.Logger.Println("运行失败", e)
		fmt.Printf("运行失败:%v", e)
		return
	}
}
